﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region SYS_EmplRole实体类
public class SYS_EmplRole
{
	private string m_EmplID;
	private string m_RoleID;
	
	public SYS_EmplRole ()
	{
		m_EmplID="";
		m_RoleID="";
	}
	
	public string EmplID
	{
		get{return m_EmplID;}
		set{m_EmplID=value;}
	}
	public string RoleID
	{
		get{return m_RoleID;}
		set{m_RoleID=value;}
	}
}
#endregion

#region SYS_EmplRole管理类
public partial class LogicLayer
{
	public bool AddSYS_EmplRole(SYS_EmplRole theSYS_EmplRole)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into SYS_EmplRole (EmplID,RoleID) values (@EmplID,@RoleID)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_EmplRole.EmplID);
			db.AddInParameter(cmd, "@RoleID", DbType.String, theSYS_EmplRole.RoleID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddSYS_EmplRole:" + ex.Message );
			return false;
		}
	}
	
	public SYS_EmplRole GetSYS_EmplRoleFromDataReader(IDataReader dataReader)
	{
		try
		{
			SYS_EmplRole result = new SYS_EmplRole();
			
			if (dataReader["EmplID"] != null && dataReader["EmplID"] != System.DBNull.Value )
				result.EmplID = (string)dataReader["EmplID"];
			if (dataReader["RoleID"] != null && dataReader["RoleID"] != System.DBNull.Value )
				result.RoleID = (string)dataReader["RoleID"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderSYS_EmplRole:" + ex.Message);
			return null;
		}
	}
	
	public SYS_EmplRole GetSYS_EmplRole(string EmplID,string RoleID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From SYS_EmplRole where EmplID=@EmplID and RoleID=@RoleID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@EmplID", DbType.String, EmplID);
			db.AddInParameter(cmd, "@RoleID", DbType.String, RoleID);
			
			SYS_EmplRole result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetSYS_EmplRoleFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetSYS_EmplRole:" + ex.Message);
			return null;
		}
	}
	
	public bool DelSYS_EmplRole(string EmplID,string RoleID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From SYS_EmplRole where EmplID=@EmplID and RoleID=@RoleID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@EmplID", DbType.String, EmplID);
			db.AddInParameter(cmd, "@RoleID", DbType.String, RoleID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelSYS_EmplRole:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateSYS_EmplRole(SYS_EmplRole theSYS_EmplRole)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update SYS_EmplRole set  where EmplID=@EmplID and RoleID=@RoleID";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_EmplRole.EmplID);
			db.AddInParameter(cmd, "@RoleID", DbType.String, theSYS_EmplRole.RoleID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateSYS_EmplRole:" + ex.Message);
			return false;
		}
	}
	
	public List<SYS_EmplRole> ListSYS_EmplRole()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from SYS_EmplRole";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<SYS_EmplRole> result = new  List<SYS_EmplRole>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					SYS_EmplRole obj = GetSYS_EmplRoleFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListSYS_EmplRole:" + ex.Message);
			return null;
		}
	}
	
}
#endregion